import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.Iterator;

/**
 * Created by zhaobo on 2016/4/7.
 */
public class Delete {
    public static String xml = "E:\\WorkSpace\\SVN\\shanpao\\Shanpao_studio\\shanpao\\build\\outputs\\lint-results-adebugDebug.xml";

    public static void main(String[] args) {
        parserXml(xml);
    }

    public static void parserXml(String fileName) {
        File inputXml = new File(fileName);
        SAXReader saxReader = new SAXReader();
        try {
            Document document = saxReader.read(inputXml);
            Element employees = document.getRootElement();

            if (employees.getName().equals("issues")) {
                for (Iterator i = employees.elementIterator(); i.hasNext(); ) {
                    Element employee = (Element) i.next();
                    if (employee.getName().equals("issue") && "UnusedResources".equals(employee.attribute("id").getValue())) {
                        for (Iterator j = employee.elementIterator(); j.hasNext(); ) {
                            Element node = (Element) j.next();
                            if("location".equals(node.getName())){
                                String path = node.attribute("file").getValue();
                                File file = new File(path);
                                if(file.exists() && !"values".equals(file.getParentFile().getName())) {
                                    System.out.println(path);
                                }
                            }
                        }
                    }
                }
            }
        } catch (DocumentException e) {
            e.printStackTrace();
        }
    }
}
